import * as VueRouter from 'vue-router'
import Error404 from '@/views/error/404.vue'
import Login from '@/views/login.vue'
import Layout from '@/components/layout.vue'
const Home = { template: '<div>Home</div>' }
const About = { template: '<div>About</div>' }

const routes = [
    { 
      path: '/home', component: Layout,
      children:[{
        path:'index',
        component:Home
      }]
    },
    { name:'About', path: '/about', component: About },
    { name:'Login',hidden: true,path: '/login/:id?', component: Login,beforeEnter(to,from,next){
      next()
    }},
    { name:'Error404' ,path: '/404',component:Error404},
    {
      path:'/:pathMatch(.*)',
      redirect:'/404'
    }
  ]
const router = VueRouter.createRouter({
    history:VueRouter.createWebHistory('/'),
    routes,
})
// router.beforeEach((to,from,next)=>{
//     if(to.name !=='Login')
//     {
//       next({name:'Login'})
//     }
//     else{
//       next()
//     }
// })
export default router